Skip to content

ENH: array_namespace: support torch.compile#413

Merged
ev-br merged 3 commits intomainfrom
lucascolley-patch-1
Apr 3, 2026
Merged

ENH: array_namespace: support torch.compile#413
ev-br merged 3 commits intomainfrom
lucascolley-patch-1

Conversation

@lucascolley
Copy link
Copy Markdown
Member

closes gh-411

@lucascolley lucascolley force-pushed the lucascolley-patch-1 branch 2 times, most recently from f52391f to b2b0911 Compare April 3, 2026 13:14
Co-authored-by: Evgeni Burovski <evgeny.burovskiy@gmail.com>
@lucascolley lucascolley force-pushed the lucascolley-patch-1 branch from b2b0911 to 053a0bc Compare April 3, 2026 13:20
@ev-br
Copy link
Copy Markdown
Member

ev-br commented Apr 3, 2026

Interesting! Any chance you checked if vendoring this version in SciPy works?

@lucascolley
Copy link
Copy Markdown
Member Author

No, but you can see it working in CI at data-apis/array-api-extra#668.

Copy link
Copy Markdown
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I ran scipy tests with this branch locally. On a CUDA enabled machine, there are some failures, but they all seem unrelated:

FAILED scipy/sparse/linalg/_isolve/tests/test_iterative.py::test_precond_dummy[rand-cmplx-sym-pd-F-cg-numpy-batch_b0-batch_A0] - AssertionError: 
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float32-ttest_1samp] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float32-ttest_rel] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float32-ttest_ind] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float32-pearsonr] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float64-ttest_1samp] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float64-ttest_rel] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float64-ttest_ind] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_hypothesis_tests[torch-float64-pearsonr] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_combine_pvalues[torch-float32-tippett] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_combine_pvalues[torch-float32-mudholkar_george] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_combine_pvalues[torch-float64-tippett] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
FAILED scipy/stats/tests/test_device_dtype.py::test_combine_pvalues[torch-float64-mudholkar_george] - TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Here's a PR to your branch with a test, #414

I think we should merge in a test, then merge this PR.

@ev-br ev-br merged commit 75ee8bc into main Apr 3, 2026
53 checks passed
@ev-br ev-br deleted the lucascolley-patch-1 branch April 3, 2026 18:22
@ev-br ev-br added this to the 1.15 milestone Apr 3, 2026
@ev-br ev-br added the enhancement New feature or request label Apr 3, 2026
@ev-br
Copy link
Copy Markdown
Member

ev-br commented Apr 3, 2026

Merged, thanks Lucas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_namespace incompatible with torch.compile due to using modules as dictionary key

2 participants